﻿/*
#------------------------------------------------------------------------------
#-- Program Name:	[dbo].[spMSX_set_server_visibility]
#-- Purpose:		Manages whether a user of the Restore Utility wants to see
#--					a server in their dropdown of servers
#--	Last Update:	09/05/2012
#--					For a complete history - please review comments in Version
#--					Control.
#------------------------------------------------------------------------------
*/
CREATE PROCEDURE [dbo].[spMSX_set_server_visibility]
(
	@rst_server_name		varchar(60),
	@is_visible				bit
)
AS

SET NOCOUNT ON

DECLARE @rst_username varchar(255)
SELECT	@rst_username = SUSER_NAME()

IF EXISTS ( SELECT TOP 1 * FROM [dbo].[tblMSX_server_restore_user] WHERE rst_server_name = @rst_server_name AND rst_username = @rst_username )
  BEGIN
	IF NOT EXISTS ( SELECT TOP 1 * FROM [dbo].[tblMSX_server_restore_user] WHERE rst_server_name = @rst_server_name AND rst_username = @rst_username AND rst_should_hide = ~@is_visible )
	  BEGIN
		UPDATE		[dbo].[tblMSX_server_restore_user]
		SET			rst_should_hide = ~@is_visible
		WHERE		rst_server_name = @rst_server_name 
					AND rst_username = @rst_username
	  END
  END
ELSE
  BEGIN
		INSERT INTO [dbo].[tblMSX_server_restore_user] VALUES (@rst_server_name, @rst_username, ~@is_visible)
  END

SET NOCOUNT OFF